package com.app.mvc.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.app.mvc.dao.CategoryDao;
import com.app.mvc.dao.DealDao;
import com.app.mvc.dao.DealImageDao;
import com.app.mvc.dao.LocationDao;
import com.app.mvc.dao.impl.CategoryDaoImpl;
import com.app.mvc.dao.impl.DealDaoImpl;
import com.app.mvc.dao.impl.DealImageDaoImpl;
import com.app.mvc.dao.impl.LocationDaoImpl;
import com.app.mvc.model.Deal;
import com.app.mvc.model.DealImage;
import com.app.mvc.model.Location;

public class Application {
	private LocationDao locationDaoImpl = new LocationDaoImpl();
	private CategoryDao categoryDaoImpl = new CategoryDaoImpl();
	private DealDao dealDaoImpl = new DealDaoImpl();
	private DealImageDao dealImageDaoImpl = new DealImageDaoImpl();

	public static void main(String[] args) {
		Application application = new Application();
		System.out.println(application.locationDaoImpl.getAll().size());

		System.out.println(application.categoryDaoImpl.getCategoryByLocation(1)
				.size());

		System.out.println("aa: "
				+ application.dealDaoImpl.getDealByCategory(1).size());
		int[] kickerNumbers = new int[5];
		for (int i = 0; i < kickerNumbers.length; i++) {
			kickerNumbers[i] = randomRange(1, 19);
			if (i > 0) {
				int temp = i - 1;
				if (kickerNumbers[temp] == kickerNumbers[i]) {
					i--;
				}
			}
			// System.out.println(kickerNumbers[i]);
		}

		// System.out.println(application.dealImageDaoImpl.getImageByDeal(1).size());
		//
		// System.out.println(application.dealDaoImpl.numsDeal());
		// System.out.println(application.dealDaoImpl.getDealByPage(0,
		// 6).size());
		// System.out.println(application.dealDaoImpl.getDealByPage(6,
		// 6).size());
		// System.out.println(application.dealDaoImpl.getDealByPage(12,
		// 6).size());
		int count = application.dealDaoImpl.numsDeal();
		int k = 1;
		int num = 2;
		int page = 0;
		int temp = 0;
		while (k < count) {
			page = count / num;
			temp = count % num;
			k++;
		}
		if (temp > 0 && temp < num) {
			page++;
		}
		List<Integer> pageNav = new ArrayList<>();
		for (int i = 1; i <= page; i++) {
			pageNav.add(i);
		}
		System.out.println(pageNav.size());
		// List<Deal> ls = application.dealDaoImpl.getDealByCategory(1);
		// for (Deal deal : ls) {
		// System.out.println(deal.getTitle());
		// }
	}

	private int[] removeElement(int[] array, int index) {
		for (int i = 0; i < array.length; i++) {

		}
		return null;
	}

	public static int randomRange(int min, int max) {
		return (int) Math.round(((Math.random() * (max - min)) + min));
	}

}
